home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
cmprss.exe
/
TEST.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-01-26
|
2KB
|
132 lines
#include <string.h>
#include <iostream.h>
#include "compress.cls"
#include "decpress.cls"
main()
{
cpofstream f1("test.out");
ofstream fd("uncomp",ios::binary | ios::out);
char str[20]="Hello world.\0";
for (int j=0;j<127;j++) // 127 so sign is not a problem
{
char c=j;
short s=j;
int i=j;
long l=j;
float f=j;
double d=j;
long double ld=j;
f1<<c<<s<<i<<l<<f<<d<<ld;
f1.put(j);
f1<<str;
f1<<&str;
f1.write(str,strlen(str)+1);
f1<<'a'<<str<<str<<'b'<<str<<'c';
fd<<c<<s<<i<<l<<f<<d<<ld;
fd.put(j);
fd<<str;
fd<<&str;
fd.write(str,strlen(str)+1);
fd<<'a'<<str<<str<<'b'<<str<<'c';
}
fd.close();
f1.close();
cpifstream f2("test.out");
for (j=0;j<127;j++) // 127, so sign is not a problem
{
cout << j << '\n';
char c;
short s;
int i;
long l;
float f;
double d;
long double ld;
f2>>c>>s>>i>>l>>f>>d>>ld;
if (c!=j) // verify all numbers OK
cout << "ERR1";
if (s!=j)
cout << "ERR2";
if (i!=j)
cout << "ERR3";
if (l!=j)
cout << "ERR4";
if (f!=j)
cout << "ERR5";
if (d!=j)
cout << "ERR6";
if (ld!=j)
cout << "ERR7";
if (f2.get()!=j)
cout << "ERR8";
memset(str,'q',13);
f2>>str;
if (strcmp(str,"Hello world."))
cout << "ERR9";
if (j & 1)
{
f2.ignore(4,256); // skip 4 bytes, don't check delimeter
}
else
{
long l;
f2>>l;
if (l!=(long)&str)
cout << "ERR19";
}
if (f2.peek()!='H') // next char should be 'H'
cout << "ERR10";
memset(str,'q',13);
f2.get(str,256,0); // stop at \0
if (strcmp(str,"Hello world."))
cout << "ERR11";
if (f2.get()!=0) // pick up terminator
cout << "ERR12";
f2.get(c);
if (c!='a')
cout << "ERR13";
memset(str,'q',13);
f2.get(str,13,'Z'); // stop after 13 chars
if (strcmp(str,"Hello world."))
cout << "ERR14";
memset(str,'q',13);
f2.getline(str,256,0); // stop at delimeter and eat it
if (strcmp(str,"Hello world."))
cout << "ERR15";
if (f2.get()!='b')
cout << "ERR16";
memset(str,'q',13); // stop after 13 bytes
f2.getline(str,13,0);
if (strcmp(str,"Hello world."))
cout << "ERR17";
if (f2.get()!='c')
cout << "ERR18";
}
f2.close();
return 0;
}